ee78cb
@@ -36,6 +36,7 @@
import org.w3c.dom.NodeList;
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
 import org.apache.camel.FallbackConverter;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.StreamCache;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.component.cxf.CxfPayload;
@@ -123,54 +124,61 @@
public final class CxfPayloadConverter {
         // use fallback type converter, so we can probably convert into
         // CxfPayloads from other types
         if (type.isAssignableFrom(CxfPayload.class)) {
-            if (!value.getClass().isArray()) {
-                Source src = null;
-                // many of the common format that can have a Source created directly
-                if (value instanceof InputStream) {
-                    src = new StreamSource((InputStream) value);
-                } else if (value instanceof Reader) {
-                    src = new StreamSource((Reader) value);
-                } else if (value instanceof String) {
-                    src = new StreamSource(new StringReader((String) value));
-                } else if (value instanceof Node) {
-                    src = new DOMSource((Node) value);
-                } else if (value instanceof Source) {
-                    src = (Source) value;
-                }
-                if (src == null) {
-                    // assuming staxsource is preferred, otherwise use the one preferred
-                    TypeConverter tc = registry.lookup(javax.xml.transform.stax.StAXSource.class, value.getClass());
-                    if (tc == null) {
-                        tc = registry.lookup(Source.class, value.getClass());
+            try {
+                if (!value.getClass().isArray()) {
+                    Source src = null;
+                    // many of the common format that can have a Source created
+                    // directly
+                    if (value instanceof InputStream) {
+                        src = new StreamSource((InputStream)value);
+                    } else if (value instanceof Reader) {
+                        src = new StreamSource((Reader)value);
+                    } else if (value instanceof String) {
+                        src = new StreamSource(new StringReader((String)value));
+                    } else if (value instanceof Node) {
+                        src = new DOMSource((Node)value);
+                    } else if (value instanceof Source) {
+                        src = (Source)value;
+                    }
+                    if (src == null) {
+                        // assuming staxsource is preferred, otherwise use the
+                        // one preferred
+                        TypeConverter tc = registry.lookup(javax.xml.transform.stax.StAXSource.class, value.getClass());
+                        if (tc == null) {
+                            tc = registry.lookup(Source.class, value.getClass());
+                        }
+                        if (tc != null) {
+                            src = tc.convertTo(Source.class, exchange, value);
+                        }
                     }
-                    if (tc != null) {
-                        src = tc.convertTo(Source.class, exchange, value);
+                    if (src != null) {
+                        return (T)sourceToCxfPayload(src, exchange);
                     }
                 }
-                if (src != null) {
-                    return (T) sourceToCxfPayload(src, exchange);
+                TypeConverter tc = registry.lookup(NodeList.class, value.getClass());
+                if (tc != null) {
+                    NodeList nodeList = tc.convertTo(NodeList.class, exchange, value);
+                    return (T)nodeListToCxfPayload(nodeList, exchange);
                 }
-            }
-            TypeConverter tc = registry.lookup(NodeList.class, value.getClass());
-            if (tc != null) {
-                NodeList nodeList = tc.convertTo(NodeList.class, exchange, value);
-                return (T) nodeListToCxfPayload(nodeList, exchange);
-            }
-            tc = registry.lookup(Document.class, value.getClass());
-            if (tc != null) {
-                Document document = tc.convertTo(Document.class, exchange, value);
-                return (T) documentToCxfPayload(document, exchange);
-            }
-            // maybe we can convert via an InputStream
-            CxfPayload<?> p;
-            p = convertVia(InputStream.class, exchange, value, registry);
-            if (p != null) {
-                return (T) p;
-            }
-            // String is the converter of last resort
-            p = convertVia(String.class, exchange, value, registry);
-            if (p != null) {
-                return (T) p;
+                tc = registry.lookup(Document.class, value.getClass());
+                if (tc != null) {
+                    Document document = tc.convertTo(Document.class, exchange, value);
+                    return (T)documentToCxfPayload(document, exchange);
+                }
+                // maybe we can convert via an InputStream
+                CxfPayload<?> p;
+                p = convertVia(InputStream.class, exchange, value, registry);
+                if (p != null) {
+                    return (T)p;
+                }
+                // String is the converter of last resort
+                p = convertVia(String.class, exchange, value, registry);
+                if (p != null) {
+                    return (T)p;
+                }
+            } catch (RuntimeCamelException e) {
+                // the internal conversion to XML can throw an exception if the content is not XML
+                // ignore this and return Void.TYPE to indicate that we cannot convert this
             }
             // no we could not do it currently
             return (T) Void.TYPE;
